package yxy.game.pm2.command.godwar;

import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.godwar;
import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.GodWarMessage;
import yxy.game.pm2.module.godwar.GodWarHandler;

/** 副本战神殿 战神殿挑战记录 */
@MessageType(proto = Command.GodWarRecord, classtype = GodWarMessage.GodWarRecordRequest.class)
public class CMD_GodWarRecord extends Command<GodWarMessage.GodWarRecordRequest> {

	@Override
	public void execute(MessageSource messageSource, GodWarMessage.GodWarRecordRequest request) {
		String playerCode = messageSource.getTag();
		int dataId = request.getId();

		GodWarMessage.GodWarRecordResponse.Builder response = GodWarMessage.GodWarRecordResponse.newBuilder();

		godwar data = DataCenter.getData(dataId, godwar.class);
		if (data == null) {
			send(messageSource, response, Result.ParamError);
			return;
		}
		Result result = new GodWarHandler().record(playerCode, data, response);

		send(messageSource, response, result);
	}

	private void send(MessageSource messageSource, GodWarMessage.GodWarRecordResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}